<template>
	<view  class="main">
		<home v-show="tabIndex === 0 && show"></home>
		<search v-show="tabIndex === 1 && show"></search>
		<about v-show="tabIndex === 2 && show"></about>
		<checking v-show="tabIndex === 3 && show"></checking>
		<my v-show="tabIndex === 4 && show"></my>
		<tabBar></tabBar>
	</view>
</template>

<script>
	import home from '@/pages/home/index.vue'
	import search from '@/pages/search/index.vue'
	import about from '@/pages/about/index.vue'
	import checking from '@/pages/checking/index.vue'
	import my from '@/pages/my/index.vue'
	import tabBar from '@/widgets/tab_bar.vue'
	export default {
		components: {
			tabBar,
			home,
			search,
			about,
			checking,
			my,
		},
		onLoad() {
			const ltmyj = this.$store.state.fonts.ltmyj
			uni.loadFontFace({
			  family: 'yshst',
			  source: `url("${ltmyj}")`,
			  global: true,
			  success(res) {
			      console.log(`yshst font load success`, res.status)
			  },
			  fail(res) {
				  console.error('yshst font load fail')
			  }
			})
			const _this = this;
			uni.login({
				provider: "weixin",
				success: function(res) {
					console.log("weixin login", res);
					const { errMsg, code } = res;
					if (errMsg === "login:ok") {
						_this.$store.dispatch("login", code);
					} else {
						uni.showModal({
							content: "微信登录失败",
							title: "提示",
						})
					}
				},
			})
			// uni.navigateTo({
			// 	url: '/pages/home/xmbDoc'
			// })
		},
		data() {
			return {
				show: true,
			}
		},
		computed: {
			tabIndex() {
				return this.$store.state.tabIndex;
			}
		},
		watch: {
			tabIndex(newVal) {
				this.show = false;
				this.$nextTick(() => {
					this.show = true;
				})
			}
		}
	}
</script>

<style>
	.main {
		background-color: #e5f2f9;
		height: 100vh;
	}
</style>